#include "../XMLTools.h"

#include "SensorMeasurement.h"

using namespace MMM;

SensorMeasurement::SensorMeasurement(float timestep, SensorMeasurementType type):
    timestep(timestep),
    type(type)
{
}

void SensorMeasurement::appendDataXML(RapidXMLWriterNodePtr node) {
    assert(node);

    RapidXMLWriterNodePtr measurementNode = node->append_node(XML::NODE_MEASUREMENT)->append_attribute(XML::ATTRIBUTE_TIMESTEP, XML::toString(timestep));
    if (type != SensorMeasurementType::MEASURED) measurementNode->append_attribute(XML::ATTRIBUTE_TYPE, type.toString());
    appendMeasurementDataXML(measurementNode);
}

std::string SensorMeasurement::toXMLString() {
    RapidXMLWriterPtr writer(new RapidXMLWriter());
    RapidXMLWriterNodePtr measurementNode = writer->createRootNode(XML::NODE_MEASUREMENT)->append_attribute(XML::ATTRIBUTE_TIMESTEP, XML::toString(timestep));
    if (type != SensorMeasurementType::MEASURED) measurementNode->append_attribute(XML::ATTRIBUTE_TYPE, type.toString());
    appendMeasurementDataXML(measurementNode);
    return writer->print(true);
}

float SensorMeasurement::getTimestep() {
    return timestep;
}

bool SensorMeasurement::isInterpolated() {
    return type == SensorMeasurementType::INTERPOLATED;
}

bool SensorMeasurement::isExtended() {
    return type == SensorMeasurementType::EXTENDED;
}

SensorMeasurementType SensorMeasurement::getType() {
    return type;
}

void SensorMeasurement::setType(SensorMeasurementType type) {
    this->type = type;
}
